package cn.doitedu.util;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class Image2Text {

    public static void main(String[] args) throws IOException {

        File dir = new File("user_portrait/data/digits/sample/");
        File[] files = dir.listFiles();
        BufferedWriter bw = new BufferedWriter(new FileWriter("user_portrait/data/digits_vec/sample/vec.txt"));

        for (File file : files) {
            BufferedImage bi = ImageIO.read(file);
            StringBuilder sb = new StringBuilder();
            String label = file.getName().split("_")[0];
            sb.append(label).append(",");
            for(int i=0;i<32;i++){
                for(int j=0;j<32;j++){
                    int rgb = bi.getRGB(j, i);
                    sb.append(rgb==-1?"0":"1").append(",");
                }
            }
            bw.write(sb.toString());
            bw.newLine();
            bw.flush();
        }


        bw.close();

    }



}
